<!--- 
	UserGateway.cfc
	Aggregate access to data
    *  Contains method that sql (select) queries that return one or more rows of data
    * Typically returns a cfquery object
    * Rarely it can return a bean (Querying by User/Pwd)
    * Performs functionality that may affect one or more rows

	Author: Felix.T
 --->

<cfcomponent output="false">
	
	
<!--- 	
	<cffunction name="getUserAttempts" access="public" returntype="query" output="false">
		<cfargument name="user_id" type="string" required="true">
		<cfreturn rc.Transfer.listByProperty("exam.attempt","user_id",Val(Arguments.user_id))>
	</cffunction>
 --->	
	<cffunction name="setRequestContent" returntype="void">
		<cfargument name="requestContent" required="true">
		<cfset variables.rc = Arguments.requestContent>
	</cffunction>

	<cffunction name="setTransfer" returntype="void">
		<cfargument name="transfer" required="true">
		<cfset variables.oTransfer = Arguments.transfer>
	</cffunction>
	
	<cffunction name="getUserByCredentials" access="public" returntype="any" output="false">
		<cfargument name="stArguments" type="struct" required="true">
		<cfreturn oTransfer.readByPropertyMap("user.user", stArguments)>
	</cffunction>
	
	<cffunction name="getUserAttempts" access="public" returntype="any" output="false">
		<cfargument name="user_id" type="numeric" required="true">
		<!---
		<cfquery name="qUserAttempts" datasource="#Application.PDS#">
			SELECT * 
			FROM attempt 
			WHERE
				user_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#Val(Arguments.userID)#">
		</cfquery>
		<cfreturn qUserAttempts>
		--->
		<cfreturn oTransfer.listByPropertyMap( "user.user", arguments )>
	</cffunction>	

	<cffunction name="getCurrentAttempt" access="public" returntype="query" output="false">
		<cfargument name="user_id" type="numeric" required="true">
		<cfsavecontent variable="tql">
			FROM attempt
			WHERE 
				user_id = #Arguments.user_id# 
				AND is_finish = 0	
		</cfsavecontent>
		<cfscript>
			query = variables.oTransfer.createQuery( tql );
			return variables.oTransfer.listByQuery( query );
		</cfscript>
	</cffunction>
<!--- 
		<cfquery name="qQuestions" datasource="#Application.PDS#" username="#Application.DBUSER#" 
				password="#Application.DBPASS#" >
			UPDATE 
				attempt_question 
			SET 
				is_correct = <cfqueryparam cfsqltype="cf_sql_bit" value="#Val(Arguments.is_correct)#">
			WHERE
				attempt_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#Val(Arguments.attempt_id)#">
				AND question_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#Val(Arguments.question_id)#">
		</cfquery>
	
 ---></cfcomponent>